import { MockMethod } from 'vite-plugin-mock';
import { mock } from 'mockjs';
import { pickOneName } from '../../common/MockNameList';
import NETWORK_DELAY from '..';

const generateAuthorizeData = () => {
  const userName = pickOneName(true);
  return mock({
    'token|10': '@word(5,5)',
    name: userName,
    id: '@natural(100000,999999)',
    avatar: '@image(80x80, @color)',
  });
};

export default [
  {
    url: '/api/authenticate',
    method: 'post',
    statusCode: 200,
    timeout: NETWORK_DELAY,
    response: () => {
      return mock({
        'token|20': '@word(5,5)',
        message: '用户名密码错误',
      });
    },
  },
  {
    url: '/api/authorize',
    method: 'post',
    statusCode: 200,
    timeout: NETWORK_DELAY,
    response: () => {
      return generateAuthorizeData();
    },
  },
  {
    url: '/api/logout',
    method: 'get',
    statusCode: 200,
    timeout: NETWORK_DELAY,
    response: () => null,
  },
  {
    url: '/api/company/register',
    method: 'post',
    statusCode: 200,
    timeout: NETWORK_DELAY,
    response: () => {
      return generateAuthorizeData();
    },
  },
] as MockMethod[];
